package com.server.server_a10.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.server.server_a10.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;


/**
 * 这个接口用来对接用户数据库操作
 */

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @SelectProvider(type = ProviderUser.class, method = "getLoginInf")
    List<User> getLoginInf();

    @SelectProvider(type = ProviderUser.class, method = "getUsersLimit")
    List<User> getUsersLimit(@Param("index") int index,@Param("limit") int limit);

    @SelectProvider(type = ProviderUser.class, method = "getUserNameLimit")
    List<User> getUserNameLimit(@Param("index")int index,@Param("limit") int limit,@Param("name") String name);

    @SelectProvider(type = ProviderUser.class, method = "getUserCount")
    int getUserCount();

    class ProviderUser {
        public static String getUsersLimit(int index,int limit) {
            return "select id,name,isAdmin,sex,address,phone,email from user limit #{index},#{limit}";
        }
        public static String getUserNameLimit(int index,int limit, String name) {
            return "select id,name,isAdmin,sex,address,phone,email from user where name like CONCAT('%',#{name},'%') limit #{index},#{limit}";
        }
        public static String getUserCount() {
            return "select count(*) from user";
        }

        public static String getLoginInf(){
            return "select id,name,isAdmin from user where id='100000' and passwd='123'";
        }
    }
}
